package com.example.classconnect.fragments;

import com.example.classconnect.R;

import android.app.Fragment;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

public class MapFragment extends Fragment {
public MapFragment() {};
	
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
 
		// NOTE --- CHANGE XML LAYOUT FILE
		 View rootView = inflater.inflate(R.layout.fragment_map, container, false);
         
        final EditText addrText = (EditText) rootView.findViewById(R.id.location);
		final Button button = (Button) rootView.findViewById(R.id.mapButton);

		button.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				try {
					String address = addrText.getText().toString();
					address = address.replace(' ', '+');
					Intent geoIntent = new Intent(
							android.content.Intent.ACTION_VIEW, Uri
									.parse("geo:0,0?q="+address));
					startActivity(geoIntent);
					
					// Show current location
					// Intent intent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("google.navigation:q="));
					// startActivity(intent);
				} catch (Exception e) {
				}
			}
		});
        
        
        return rootView;
    }
	
	@Override
	public void onStart() {
		super.onStart();
		
		//Log.i(TAG, "The activity is about to become visible.");
	}

	@Override
	public void onResume() {
		super.onResume();
		//Log.i(TAG, "The activity has become visible (it is now \"resumed\")");
	}

	@Override
	public void onPause() {
		super.onPause();
		//Log.i(TAG,"Another activity is taking focus (this activity is about to be \"paused\")");
	}

	@Override
	public void onStop() {
		super.onStop();
		//Log.i(TAG, "The activity is no longer visible (it is now \"stopped\")");
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		//Log.i(TAG, "The activity is about to be destroyed.");
	}
	
}
